<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>


  <div class="box">
    <p>姓名</p>
    <button class="start">开始</button>
    <button class="end">结束</button>

    
  </div>


  <script>

    const arr = ["陈政睿", "钟芳艳", "艾轶群", "周胜", "段晓倩"]

    const start = document.querySelector('.start')
    const end = document.querySelector('.end')
    const p = document.querySelector('p')

    let time = 0
    let ran = 0
    //开始
    start.addEventListener('click', function () {
      time = setInterval(function () {
        ran = Math.floor(Math.random() * arr.length)
        // console.log(ran)
        p.innerHTML = arr[ran]
      }, 1)
      if (arr.length === 1) {
        start.disabled = 'true'
        end.disabled = 'true'
        alert('只剩下一个数据')
      }
    })

    //结束
    end.addEventListener('click', function () {
      clearInterval(time)
      arr.splice(ran, 1)
      console.log(arr)
    })

  </script>

</body>

</html>